<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">点击我触发惊喜</button>
</body>
<!-- 
设计一个按钮，当用户连续点击该按钮时，使用节流技术确保处理函数不会在短时间内被重复执行多次。
 -->
<script>
    document.querySelector("#btn").addEventListener('click', throttle(function () {
        console.log('惊喜惊喜惊喜惊喜');

    }, 3000))
    function throttle(fn, time) {
        var start = Date.now();
        return function () {
            var end = Date.now();
            if (end - start > time) {
                fn();
                start = Date.now();
            }

        }
    }



</script>

</html>